
*************************************************************************************;

/* 		This file produce the results of Table 7 Panel A: Trading Intensity			*/

*************************************************************************************;

libname rep "C:\Users\~";

data regbase; set rep.mydata; run;

%macro print;
data N; set N; Estimate = nValue1; if Label1 = "Used"; run;
data Nobs; set N; Parameter = "N"; keep EstType Parameter Estimate; run;
data r2; set fit; Parameter = "RSQ"; keep EstType Parameter RSquare; rename RSquare = Estimate;  run;
data final; set parest Nobs r2; drop EstType StdErr Probt DF; run;
data final&i; set final; rename Estimate = &type tValue = t_&type; 
if Parameter not in ("flow_all", "flow_low", "flow_high", "N", "RSQ") then delete; run;
%mend;

%macro all ;
%do i=1 %to 2;
%if &i =1 %then %do; %let type = hf; %let flow = hfflow; %end; 
%else %do; %let type = mf; %let flow = active; %end;
ods output "Nonlinear GMM Summary of Residual Errors" = fit;
ods output "Nonlinear GMM Parameter Estimates" = parest;
ods output "Estimation Summary Statistics" = N;
proc model data=regbase plot =none;
endo Inten_&type ; exog &flow mktrf amihud tover hml smb ; instruments _exog_;
Inten_&type =flow_all *&flow +b1*mktrf + b2*amihud +b3*tover + b4*hml +b5*smb +b0  ;
fit Inten_&type / gmm kernel=(bart,13,0) vardef=n; run; quit; 
%print;
%end;
data T7A_ttl; merge final1 final2; run;
%mend;

%macro decomp;
%do i=1 %to 2;
%if &i =1 %then %do; %let type = hf; %let flow = hfflow; %end; 
%else %do; %let type = mf; %let flow = active; %end;
ods output "Nonlinear GMM Summary of Residual Errors" = fit;
ods output "Nonlinear GMM Parameter Estimates" = parest;
ods output "Estimation Summary Statistics" = N;
proc model data=regbase plot =none;
endo Inten_&type ; exog &flow._low &flow._high mktrf amihud tover hml smb ; instruments _exog_;
Inten_&type = flow_low *&flow._low + flow_high*&flow._high +b1*mktrf +b2*amihud +b3*tover + b4*hml +b5*smb +b0 ;
fit Inten_&type / gmm kernel=(bart,13,0) vardef=n; run; quit; 
%print;
%end;

data T7A_freq; merge final1 final2; run;
%mend;

%all;
%decomp;

proc print data = T7A_ttl noobs; run;

proc print data = T7A_freq noobs; run;
